﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenericLibrariesToolKit;
using Utils;

namespace Model
{
    /// <summary>
    /// 出版物实体
    /// </summary>
    public class Publication
    {        
        /*出版物ID*/
        public string PublicationId { get; set; }
        /*出版物标题*/
        public string PublicationTitle { get; set; }
        /*出版物作者*/
        public string PublicationAuthor { get; set; }
        /*出版物类型*/
        public string PublicationType { get; set; }
        /*出版物描述*/
        public string PublicationDescription { get; set; }
        /*出版物价格*/
        public float PublicationPrice { get; set; }
        /*出版物日期*/
        private string publicationDate = DateTimeUtil.GetDateTime();
        public string PublicationDate
        {
            get { return publicationDate; }
            set { publicationDate = value; }
        }
        /*点击量*/
        public long PublicationClickAmount { get; set; }


        /// <summary>
        /// 应用程序启动时，实体管理器将会调用此方法进行初始化。
        /// </summary>
        public void Intialization()
        {
            //声明一个实体实体对象
            Entity entity = new Entity();

            //指定该实体对应数据库中的表名
            entity.TableName = "T_PUBLICATION";
            //指定该实体的标识符
            entity.EntityId = "PublicationId";
            //指定主键生成策略
            entity.Generator = GenericLibrariesToolKit.Enumeration.PKGenerationStrategy.GUID;
            ///实体关系映射字典
            ///key:实体属性名称，value:对应的数据库中表的字段名
            Dictionary<string, string> dictionary = new Dictionary<string, string>();


            dictionary.Add("PublicationId", "PUBLICATION_ID");
            dictionary.Add("PublicationTitle", "PUBLICATION_TITLE");
            dictionary.Add("PublicationAuthor", "PUBLICATION_AUTHOR");
            dictionary.Add("PublicationType", "PUBLICATION_TYPE");
            dictionary.Add("PublicationDescription", "PUBLICATION_DESCRIPTION");
            dictionary.Add("PublicationPrice", "PUBLICATION_PRICE");
            dictionary.Add("PublicationDate", "PUBLICATION_DATE");
            dictionary.Add("PublicationClickAmount", "PUBLICATION_CLICK_AMOUNT");

            //赋值
            entity.ORMDictionary = dictionary;

            //将实体加入实体管理器，
            EntityManager.GetInsatnce().AddEntity("Model.Publication", entity);
        }
    }
}
